/*
* ==========================================底层数据层==========================================
* ==========================================用户数据块==========================================
* 1.各个用户信息类，包含了用户的信息，包括用户的id，姓名，密码，权限位，角色，角色描述
* 2. 各个用户提供序列化接口和反序列化接口，用于将用户信息存储到文件中，或者从文件中读取用户信息
* 3. 各个用户提供权限校验接口，用于校验用户的权限
* 4. 各个用户提供密码修改接口，用于修改用户的密码
* 5. 权限枚举类和角色枚举
* ==========================================用户数据块==========================================
* ==========================================底层数据层==========================================
*/

#ifndef USER_H
#define USER_H

#include <QWidget>
#include <QHash>
#include <QDebug>
#include <string>
#include <cstdint>
#include <memory>

class User;

typedef uint16_t PB_t;//未来可能会扩充权限
typedef std::shared_ptr<User> MYPTR_T;

/*==========================================<枚举>==========================================*/


enum class Role//角色枚举，管理员创建用户时使用
{
    ADMIN=1,
    USER_INFO,
    USER_STORE_IO,
    USER_STORE_CHECK
};

inline const QHash<QString,Role> roleMap =
{
        {"ADMIN",Role::ADMIN},
        {"USER_INFO",Role::USER_INFO},
        {"USER_STORE_IO",Role::USER_STORE_IO},
        {"USER_STORE_CHECK",Role::USER_STORE_CHECK},
};
inline const QHash<Role,QString> reRoleMap =
{
        {Role::ADMIN,"ADMIN"},
        {Role::USER_INFO,"USER_INFO"},
        {Role::USER_STORE_IO,"USER_STORE_IO"},
        {Role::USER_STORE_CHECK,"USER_STORE_CHECK"},
};

enum class UPBits//角色权限位枚举
{
    //管理员权限位
    USER_ADMIN_ADD = (PB_t)0x0001 << 0,
    USER_ADMIN_DELETE = (PB_t)0x0001 << 1,
    USER_ADMIN_MODIFY = (PB_t)0x0001 << 2,
    USER_ADMIN_FIND = (PB_t)0x0001 << 3,
    USER_ADMIN_SHOW = (PB_t)0x0001 << 4,
    USER_ADMIN_SAVE = (PB_t)0x0001 << 5,
    USER_ADMIN_LOG = (PB_t)0x0001 << 6,
    USER_ADMIN_ALL = (PB_t)0xFFFF,


    //录入配件人员权限位
    USER_INFO_ADD = (PB_t)0x0001 << 0,
    USER_INFO_DELETE = (PB_t)0x0001 << 1,
    USER_INFO_MODIFY = (PB_t)0x0001 << 2,
    USER_INFO_FIND = (PB_t)0x0001 << 3,
    USER_INFO_SHOW = (PB_t)0x0001 << 4,
    USER_INFO_ASSIGNING = (PB_t)0x0001 << 5,
    USER_INFO_ALL = (PB_t)0xFFFF,

    //仓库管理人员权限位
    USER_SIO_IN_ADD = (PB_t)0x0001 << 0, 
    USER_SIO_IN_DELETE = (PB_t)0x0001 << 1,
    USER_SIO_IN_MODIFY = (PB_t)0x0001 << 2,
    USER_SIO_IN_FIND = (PB_t)0x0001 << 3,
    USER_SIO_IN_SHOW = (PB_t)0x0001 << 4,
    USER_SIO_IN_ALL = (PB_t)0x001F,

    USER_SIO_OUT_ADD = (PB_t)0x0001 << 5,
    USER_SIO_OUT_DELETE = (PB_t)0x0001 << 6,
    USER_SIO_OUT_MODIFY = (PB_t)0x0001 << 7,
    USER_SIO_OUT_FIND = (PB_t)0x0001 << 8,
    USER_SIO_OUT_SHOW = (PB_t)0x0001 << 9,
    USER_SIO_OUT_ALL = (PB_t)USER_SIO_OUT_ADD|USER_SIO_OUT_DELETE|USER_SIO_OUT_MODIFY|USER_SIO_OUT_FIND|USER_SIO_OUT_SHOW,

    USER_SIO_OPERATION_IN = (PB_t)0x0001 << 10,
    USER_SIO_OPERATION_OUT = (PB_t)0x0001 << 11,
    USER_SIO_ALL = (PB_t)0xFFFF,

    //仓库盘点人员权限位
    USER_SCK_START_CHECK = (PB_t)0x0001,
    USER_SCK_SHOW_CHECK = (PB_t)0x0001 << 1,
    USER_SCK_SHOW_HISCHECK = (PB_t)0x0001 << 2,
    USER_SCK_AFFRIM = (PB_t)0x0001 << 3,
    USER_SCK_ALL = (PB_t)0xFFFF,
};

/*==========================================<用户信息基类>==========================================*/
class User
{
protected:
    int id;
    QString name;
    QString password;
    PB_t permissionBits;
    Role role;
    QString roleDescription;

public:
    User() = default;
    User(const int& id, const QString& name, const QString& password, PB_t permissionBits, const QString& roleDescription);
    User(const QString& name, const QString& password, PB_t permissionBits, Role role, const QString& roleDescription);
    virtual ~User();
    
    int getId()const;
    QString getName()const;
    QString getPassword()const;
    PB_t getPermissionBits()const;
    Role getRole()const;
    QString getRoleDescription()const;

    void setPermissionBits(PB_t permissionBits);
    void setRole(Role role);

    virtual bool check_permission(UPBits pb);
};


#endif
